AirQuality Scheduler

工作流概述

这是一个包含12个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "PcVz6j5XLU7Z9MPN",
  "meta": {
    "instanceId": "7182053c6096cf2c9d8885665d447ff4ab0753f89cf41ab8a36a48ee405e4b1c",
    "templateCredsSetupCompleted": true
  },
  "name": "AirQuality Scheduler",
  "tags": [],
  "nodes": [
    {
      "id": "ea677d9c-fa79-4897-be4d-6b9793050775",
      "name": "Get Air data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        480,
        0
      ],
      "parameters": {
        "url": "https://api.ambeedata.com/latest/by-lat-lng",
        "options": {
          "redirect": {
            "redirect": {}
          }
        },
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "lat",
              "value": "={{ $('Set Your Location Coordinates').item.json.lat }}"
            },
            {
              "name": "lng",
              "value": "={{ $('Set Your Location Coordinates').item.json.lng }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "1709ec3a-4306-4987-ada3-7b23ad50b432",
      "name": "Get Pollen data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        720,
        0
      ],
      "parameters": {
        "url": "https://api.ambeedata.com/latest/pollen/by-lat-lng",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "lat",
              "value": "={{ $('Set Your Location Coordinates').item.json.lat }}"
            },
            {
              "name": "lng",
              "value": "={{ $('Set Your Location Coordinates').item.json.lng }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "10dd46a2-fcdc-4246-a9be-1230527266b3",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        940,
        0
      ],
      "parameters": {
        "text": "Follow the prompt below",
        "options": {
          "systemMessage": "= Hey there! You're a kind and helpful assistant here to make environmental health information easy to understand and act on 💚

You'll receive two things:
1️⃣ Real-time environmental data (air quality and pollen levels)  
2️⃣ A short user profile (to help tailor your suggestions)

Your job is to:
✨ Summarize today’s environmental conditions  
🌿 Give smart, caring suggestions based on who the user is  

---

📍 Here’s the environmental data you’ll get:
<environmental_data>
🌍 *Location:*  
• Country: {{ $('Get Air data').item.json.stations[0].countryCode }}  
• City: {{ $('Get Air data').item.json.stations[0].city }}  
• Lat/Lng: {{ $('Get Air data').item.json.stations[0].lat }}, {{ $('Get Air data').item.json.stations[0].lng }}

💨 *Air Quality:*  
• PM2.5: {{ $('Get Air data').item.json.stations[0].PM25 }} µg/m³  
• AQI: {{ $('Get Air data').item.json.stations[0].AQI }}  
• Main pollutant: {{ $('Get Air data').item.json.stations[0].aqiInfo.pollutant }}  
• Level: {{ $('Get Air data').item.json.stations[0].aqiInfo.category }}

🌸 *Pollen Levels:*  
• Tree pollen: {{ $json.data[0].Count.tree_pollen }} ({{ $json.data[0].Risk.tree_pollen }})  
• Grass pollen: {{ $json.data[0].Count.grass_pollen }} ({{ $json.data[0].Risk.grass_pollen }})  
• Weed pollen: {{ $json.data[0].Count.weed_pollen }} ({{ $json.data[0].Risk.weed_pollen }})
</environmental_data>

---

👧 And here’s the person you’re helping today:
<user_profile>   
• Age:  {{ $('Set User Profile').item.json['Age '] }} 
• Health Sensitivity: {{ $('Set User Profile').item.json['Health sensitivities'] }}
</user_profile>

---

💡 What to do:

1. 📝 **Write a friendly summary**  
Explain the overall environmental situation today in 2–3 warm, simple sentences.  
Be sure to:
- Mention if it’s generally a good or sensitive day to be outdoors.
- Highlight anything unusually high (e.g., \"Tree pollen is very high today\" or \"Air quality is moderate\").
- **Include the actual environmental values** (like pollen risk levels: grass_pollen = {{ $json.data[0].Risk.grass_pollen }}, tree_pollen = ..., and AQI = {{ $('Get Air data').item.json.stations[0].AQI }}) clearly in your response.  
Make the summary sound supportive and easy to understand, like talking to a friend or parent.

2. 🌟 **Give 3 to 5 helpful suggestions**  
Think like someone who really cares.  
Keep them practical, gentle, and specific to the user.  
Examples: stay indoors, wear a mask, take medication, keep windows closed, use a purifier etc.....

---

📦 Format your response like this (with emojis and clarity!) of course ignore 
---
3. Use the Mail Tool to send the message by email
✨ Stay warm, helpful, and comforting.  
Everything you say should feel like advice from someone who truly cares.  
Only use the data and profile provided — no guesses or outside info.
"
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "a4db1c0e-b61b-40cf-a7e7-b2cc0b8be481",
      "name": "Think",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        1060,
        240
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "86d89626-68e3-4718-b86c-84acc644a87d",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        900,
        240
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "gpt-4.1"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "bVTwohZmhBo54IXz",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "1bcaf417-dc1c-40a7-be01-f9bd64c4db46",
      "name": "Gmail",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        1180,
        240
      ],
      "webhookId": "bcf8b4a4-4adf-4e30-a962-683173e5b442",
      "parameters": {
        "sendTo": "simoroosvelt@gmail.com",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
        "options": {},
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Subject', ``, 'string') }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "cfzmH8MNbSo1rgbX",
          "name": "Gmail account 3"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "a7ad5577-1f1d-4b69-a869-95fd5634fd7d",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -320,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 7
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d8276f52-0850-4c93-a834-340acc55f273",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -820,
        -360
      ],
      "parameters": {
        "width": 440,
        "height": 520,
        "content": "## How to Get Your Ambee API Key
Ambee offers free API access, but you need to sign up using a work or university email address (e.g., name@company.com, name@uni.edu). Personal emails like Gmail or Outlook won't be accepted.

Steps to get your key:

1.Go to https://www.getambee.com

2.Click “Try API for Free”

3.Use your organization or school email when signing up

4.Confirm your email and copy the key from your dashboard

5.Paste it into the HTTP Request node headers:

x-api-key: YOUR_KEY_HERE
 Tip: If you’re a student, your university email usually works just fine.

"
      },
      "typeVersion": 1
    },
    {
      "id": "91f908f7-71e6-49f6-84f7-0fe00328c5e3",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -180,
        220
      ],
      "parameters": {
        "color": 4,
        "width": 480,
        "height": 300,
        "content": "## Set Your Location Coordinates 
Location Coordinates (Latitude & Longitude)
To fetch accurate air and pollen data, you need to input the coordinates of the location you're monitoring.

Example (Braunschweig, Germany):
- lat: 52.267
- lng: 10.533

You can find coordinates using Google Maps or any GPS service."
      },
      "typeVersion": 1
    },
    {
      "id": "68a7a76f-3154-443b-817f-6f284528c73b",
      "name": "Set Your Location Coordinates",
      "type": "n8n-nodes-base.set",
      "position": [
        0,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "5a40fdf6-bd34-452c-8290-7583f025fc6b",
              "name": "lat",
              "type": "string",
              "value": "52.267"
            },
            {
              "id": "4b47ebc4-f061-4906-9d15-36acb931035f",
              "name": "lng",
              "type": "string",
              "value": "10.533"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "aa5fd195-2194-48f2-a07c-b263313ef98b",
      "name": "Set User Profile",
      "type": "n8n-nodes-base.set",
      "position": [
        240,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "90a7552c-8c06-4ff5-b3c0-af992ef01f36",
              "name": "Age ",
              "type": "string",
              "value": "25"
            },
            {
              "id": "20740f05-5b99-4e90-afaa-7ef49f62448f",
              "name": "Health sensitivities",
              "type": "string",
              "value": "Allergic to Pollen"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "96eb2b9b-dc91-4853-899a-3d6d729d28a4",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        -380
      ],
      "parameters": {
        "color": 6,
        "width": 480,
        "height": 300,
        "content": "## Set  User Profile
This tells the AI what kind of user you're creating suggestions for.
It should include:
-Age
-Health sensitivities (e.g., asthma, allergy to pollen)

you can add more Infos, if you want.
"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "b8c19f31-e844-4c25-8720-58679f240705",
  "connections": {
    "Gmail": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Think": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        []
      ]
    },
    "Get Air data": {
      "main": [
        [
          {
            "node": "Get Pollen data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Pollen data": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Set Your Location Coordinates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set User Profile": {
      "main": [
        [
          {
            "node": "Get Air data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set Your Location Coordinates": {
      "main": [
        [
          {
            "node": "Set User Profile",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Httprequest
  • @N8N/N8N Nodes Langchain.Agent
  • @N8N/N8N Nodes Langchain.Toolthink
  • @N8N/N8N Nodes Langchain.Lmchatopenai
  • Gmailtool

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作